package org.dream.util;



/**
 * @author qiuriyuchen E-mail:panpan_001@126.com
 */
/** 
 * 提供数学统计工具. 
 * @author Turbo Chen 
 */
public class MathUtil {

	public static double max(double[] d) throws InvalidDataException {
		if (d == null)
			throw new InvalidDataException();
		double temp = d[0];
		for (int i = 0; i < d.length; i++) {
			if (d[i] > temp)
				temp = d[i];
		}
		return temp;
	}

	public static double min(double[] d) throws InvalidDataException {
		if (d == null)
			throw new InvalidDataException();
		double temp = d[0];
		for (int i = 0; i < d.length; i++) {
			if (d[i] < temp)
				temp = d[i];
		}
		return temp;
	}

	public static int max(int[] d) throws InvalidDataException {
		if (d == null)
			throw new InvalidDataException();
		if (d == null)
			throw new InvalidDataException();
		int temp = d[0];
		for (int i = 0; i < d.length; i++) {
			if (d[i] > temp)
				temp = d[i];
		}
		return temp;
	}

	public static int min(int[] d) throws InvalidDataException {
		if (d == null)
			throw new InvalidDataException();
		if (d == null)
			throw new InvalidDataException();
		if (d == null)
			throw new InvalidDataException();
		int temp = d[0];
		for (int i = 0; i < d.length; i++) {
			if (d[i] < temp)
				temp = d[i];
		}
		return temp;
	}

	public static String format(double value, String pattern) {
		java.text.DecimalFormat df = new java.text.DecimalFormat(pattern);
		return df.format(value);
	}

}
